import request from '@/utils/request';
import _tools from '@/utils/_tools';
function ajax(obj) {
    let { url, data, method } = obj;
    let index = url.lastIndexOf("\/");
    url = url.substring(index + 1, url.length);
    // 包含文件处理
    if (data instanceof FormData) {
        let formdata = new FormData();
        console.log(data, "formdata")
        let data_ = {};
        data.forEach((k, i) => {
            console.log(k,"------------------------")
            if (k instanceof File) {
                formdata.append(i, k);
                return;
            }
            // data_[i] = k;
            data_ = JSON.parse(k);
        })
        data_['func'] = url;
        data_ = _tools.ident(data_);
        data_ = JSON.stringify(data_);
        data_ = _tools.encrypt(data_);
        formdata.append('data', data_);
        return request({
            url: obj.url,
            method: method || 'post',
            data: formdata
        })
    }

    // 无文件请求
    data = data || {};
    console.log(data, "传递参数", url);
    data['func'] = url;
    data = _tools.ident(data);
    data = JSON.stringify(data);
    data = _tools.encrypt(data);
    // process.env.VUE_APP_BASE_API + 
    return request({
        url: obj.url,
        method: method || 'post',
        data: { data }
    })
}
export default ajax;